package com.gxa.controller.investment;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.Result;
import com.gxa.dto.investmentDto.ProjectDto;
import com.gxa.entity.commnotice.Notice;
import com.gxa.entity.investment.Project;
import com.gxa.service.investment.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 项目管理——项目公海——新增项目 前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-17 03:04:36
 */
@Api(tags = "项目管理/项目公海")
@RestController
@RequestMapping("/project")
public class ProjectController {
    @Autowired
    private ProjectService projectService;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("列表接口")
    @GetMapping("/list/{pageNum}/{pageSize}")
    public Result<PageInfo> seletAll(@PathVariable("pageNum") Integer pageNum,
                                     @PathVariable("pageSize") Integer pageSize){
    PageInfo<Project> pageInfo = this.projectService.seletAll(pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("按id查询")
    @GetMapping("/queryById/{id}")
    public Result queryById(@PathVariable("id") Integer id){
        return Result.success(projectService.queryById(id));
    }


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("增加接口")
    @PostMapping("/add")
    public Result add(@RequestBody Project project){
        int results = projectService.add(project);
        if (results == 1){
            return Result.success("add success");
        }else {
            return Result.failed("add failed");
        }
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑接口")
    @PutMapping("/dispatch")
    public Result dispatch(@RequestBody Project project){
        int results = projectService.update(project);
        if (results == 1){
            return Result.success("add success");
        }else {
            return Result.failed("add failed");
        }
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("批量分派接口")
    @PutMapping("/update")
    public Result update(@RequestBody Project project){
        int results = projectService.update(project);
        if (results == 1){
            return Result.success("add success");
        }else {
            return Result.failed("add failed");
        }
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("项目公海条件查询接口")
    @PostMapping("/getList")
    public Result getList(@RequestBody ProjectDto projectDto, @RequestParam("pageNumber") Integer pageNumber,@RequestParam("pageSize") Integer pageSize){
        try {
            PageInfo<Project> projectList = this.projectService.queryByCondition(projectDto, pageNumber, pageSize);
            return Result.success(projectList);
        }catch (Exception e){
            e.printStackTrace();
            return Result.failed("没有数据");
        }
    }
}
